const DynamicProgramming = require("../template")

function testDynamicProgrammingBasic() {
  const dp = new DynamicProgramming()

  console.log(
    "1. 斐波那契数列基础测试:",
    (() => {
      const testCases = [0, 1, 2, 3, 4, 5]
      const expected = [0, 1, 1, 2, 3, 5]
      return testCases.every((n, index) => dp.fibonacci(n) === expected[index])
    })()
  )

  console.log(
    "2. 斐波那契数列大数测试:",
    (() => {
      return dp.fibonacci(10) === 55 && dp.fibonacci(15) === 610
    })()
  )

  console.log(
    "3. 斐波那契数列迭代版本:",
    (() => {
      const testCases = [0, 1, 2, 3, 4, 5]
      const expected = [0, 1, 1, 2, 3, 5]
      return testCases.every((n, index) => dp.fibonacciIterative(n) === expected[index])
    })()
  )

  console.log(
    "4. 爬楼梯问题基础测试:",
    (() => {
      const testCases = [1, 2, 3, 4, 5]
      const expected = [1, 2, 3, 5, 8]
      return testCases.every((n, index) => dp.climbStairs(n) === expected[index])
    })()
  )

  console.log(
    "5. 爬楼梯问题大数测试:",
    (() => {
      return dp.climbStairs(10) === 89 && dp.climbStairs(15) === 987
    })()
  )

  console.log(
    "6. 最大子数组和正数数组:",
    (() => {
      const arr = [1, 2, 3, 4, 5]
      return dp.maxSubArray([...arr]) === 15
    })()
  )

  console.log(
    "7. 最大子数组和负数数组:",
    (() => {
      const arr = [-2, -1, -3]
      return dp.maxSubArray([...arr]) === -1
    })()
  )

  console.log(
    "8. 最大子数组和混合数组:",
    (() => {
      const arr = [-2, 1, -3, 4, -1, 2, 1, -5, 4]
      return dp.maxSubArray([...arr]) === 6
    })()
  )

  console.log(
    "9. 硬币找零基础测试:",
    (() => {
      const coins = [1, 3, 4]
      return dp.coinChange([...coins], 6) === 2
    })()
  )

  console.log(
    "10. 硬币找零无解情况:",
    (() => {
      const coins = [2]
      return dp.coinChange([...coins], 3) === -1
    })()
  )

  console.log(
    "11. 硬币找零零金额:",
    (() => {
      const coins = [1, 2, 5]
      return dp.coinChange([...coins], 0) === 0
    })()
  )

  console.log(
    "12. 硬币找零复杂情况:",
    (() => {
      const coins = [1, 2, 5]
      return dp.coinChange([...coins], 11) === 3
    })()
  )

  console.log(
    "13. this上下文斐波那契测试:",
    (() => {
      const dpObj = {
        multiplier: 2,
        processFibonacci: function(n) {
          const dp = new DynamicProgramming()
          return dp.fibonacci(n) * this.multiplier
        }
      }
      return dpObj.processFibonacci(5) === 16 // 8 * 2 = 16
    })()
  )

  console.log(
    "14. 复杂对象this绑定测试:",
    (() => {
      const dpConfigObj = {
        config: { base: 3 },
        processWithConfig: function(n) {
          const dp = new DynamicProgramming()
          return dp.climbStairs(n) + this.config.base
        }
      }
      return dpConfigObj.processWithConfig(3) === 6 // 3 + 3 = 6
    })()
  )

  console.log(
    "15. 动态规划性能测试:",
    (() => {
      const start = Date.now()
      dp.fibonacci(30)
      const end = Date.now()
      return (end - start) < 1000 // 应该在1秒内完成
    })()
  )
}

testDynamicProgrammingBasic()
